#include "udpserver.hpp"
#include "inetaddr.hpp"
#include "rounte.hpp"
#include "threadpool.hpp"
using namespace hlrounte;
using namespace ThreadPool;
using task_t = std::function<void()>;
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << argv[0] << " port" << std::endl;
        return -1;
    }
    uint16_t port = std::stoi(argv[1]);
    // 消息路由
    Rounte r;
    // 线程池
    std::unique_ptr<Threadpool<task_t>> thp = std::make_unique<Threadpool<task_t>>();
    thp->Start();
    // 网络通信
    UdpServer usvr(port, [&r, &thp](int sockfd, const std::string &massage, InetAddr &addr)
                   {
        auto b = std::bind(&Rounte::SendTask,&r,sockfd,massage, addr);
        thp->Enqueue(b); });
    usvr.Init();
    usvr.Start();
    return 0;
}